<?php
defined('IN_MAIN') or exit('Invalid Access!');

function prepare_prod_for_display_from_sess_cart(){
/*
This function prepare the $prods for formatting later using the $_SESSION[cart], input as unescaped (need to escape)
$_SESSION[cart][index][refno]
$_SESSION[cart][index][qty]

and the output will be

$prods[index][product detail]
if product is a jumpstart package, then it will be
$prods[index][product detail]
$prods[index][js_prod][index2][product detail]

product detail includes id, refno, title, pv, qty, prod_type (j/n) unescaped
*/

global $vars;
$db=$vars["db"];

for($i=0,$t=count($_SESSION["cart"]);$i<$t;$i++){
 $this_prod=@mysql_fetch_assoc(mysql_query("select * from $db->products where refno='".mysql_real_escape_string($_SESSION["cart"][$i]["refno"])."'")) or false;
 if($this_prod){
  $dprods[$i] = $this_prod;
  $dprods[$i]["qty"] = $_SESSION["cart"][$i]["qty"];
  //jumpstart package
  if($this_prod["prod_type"]=="j"){
   $points=array("pv","bv","dpwm","dpem","rpwm","rpem","dpi","rpi");
   foreach($points as $point_type){
    if($this_prod[$point_type."_fix"]!='y'){
     $dprods[$i][$point_type]=calc_js_prod_point($point_type, $this_prod["id"]);
    }
   }
   $t2=@mysql_num_rows($r2=mysql_query("select p.id, p.refno, p.title, p.pv, p.prod_type, j.qty from $db->jumpstart_detail j, $db->products p where j.jid='$this_prod[id]' and j.pid=p.id"));
   for($j=0;$j<$t2;$j++){
    $this_js_prod=mysql_fetch_assoc($r2);
    $dprods[$i]["js_prod"][$j] = $this_js_prod;
   }
  }
 }
}

return $dprods;
}
?>